﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Basic4Net.BusinessRules;
using Basic4Net.Entities;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Base
{
    public partial class FixedWordLoadSet : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }


        private void Bind()
        { 
           List<t_Post> list = Post.PostInstance.FindAll(SchoolMark);

           Repeater1.DataSource = list;
           Repeater1.DataBind();
        }

        /// <summary>
        /// 验证职务名称是否重复
        /// </summary>
        /// <param name="postName"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int ValidateItemName(string postName)
        {
            t_Post item = new t_Post();
            item.PostName = postName;
            item.SchoolMark = SchoolMark;

            int n = Post.PostInstance.FindCount(item);
            return n;
        }

        /// <summary>
        /// 创建一个职务
        /// </summary>
        /// <param name="postName"></param>
        /// <param name="convertNum"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int Insert(string postName, double convertNum)
        {
            string msg = "";
            t_Post item = new t_Post();
            item.PostName = postName;
            item.ConvertNum = convertNum;
            item.SchoolMark = SchoolMark;


            if (Post.PostInstance.Add(item, ref msg))
                return 1;
            else
                return -1;
        }

        /// <summary>
        /// 删除职务
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int DeleteByID(int rid)
        {
            string msg = "";
            t_Post item = new t_Post();
            item.RID = rid;

            if (Post.PostInstance.Delete(item, ref msg))
                return 1;
            else
                return 0;
        }

        /// <summary>
        /// 更新职务信息
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static int UpdateInfo(int rid,string postName,double convertNum)
        {
            string msg = "";
            t_Post item = new t_Post();
            item.RID = rid;
            item.PostName = postName;
            item.ConvertNum = convertNum;


            if (Post.PostInstance.Update(item, ref msg))
                return 1;
            else
                return 0;
        }


        protected void btnItemBind_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}